package com.dianzhihan.cashier.model.user;

import com.dianzhihan.cashier.controller.ErrorRedirectException;
import com.dianzhihan.cashier.model.AbsValidator;
import org.springframework.stereotype.Component;

/**
 * @author Dianzhi Han
 * @version 1.0
 * @description: 用户名的合法性校验
 * @date 2023/2/5 19:19
 */

@Component
public class UsernameValidator extends AbsValidator {
    @Override
    public String validate(String username, String module, String redirectUrl) {
        username =  super.validate(username, module, redirectUrl);

        if (username.length() > 50) {
            throw new ErrorRedirectException("username的长度超过 50",module,redirectUrl);
        }

        return username;
    }
}
